initMainMap();

function initMainMap() {
    map = new BMap.Map("b-map", {
        enableMapClick: false
    });
    // 在创建地图实例后，我们需要对其进行初始化，BMap.Map.centerAndZoom()方法要求设置中心点坐标和地图级别。 地图必须经过初始化才可以执行其他操作。
    map.centerAndZoom(new BMap.Point(110.099, 18.53), 12); //110.00, 18.53
    map.setCurrentCity("陵水黎族自治县");
    map.enableScrollWheelZoom(); //启用滚轮放大缩小，默认禁用
    initSectionPoint();

}

//初始化地图中的标段坐标
function initSectionPoint() {
    setTimeout(function () {
        var projectData = [{
            "sectionGenus": "subject_category_01",
            "zlgovUnitName": "陵水黎族自治县建设工程质量监督站",
            "provinceCode": "460000",
            "origin": "rklx_2",
            "buildingUnitName": "陵水县建设单位",
            "sectionArea": "460100",
            "sectionCode": "ZHGD46AL1000071000072",
            "sectionId": "402881896ae395b3016ae3c79f73001c",
            "sectionAddress": "陵水",
            "sectionName": "海南清水湾B11-1、B11-2区2栋公寓、4栋高层及地下车库工程",
            "aqgovUnitName": "陵水黎族自治县建设工程质量监督站",
            "areaCode": "460101",
            "supervisionUnitName": "陵水县监理单位",
            "sectionXxjd": "xxjd_202",
            "sectionGenusName": "房地产项目",
            "constructionUnitName": "陵水县施工企业",
            "gpsX": "110.099081",
            "gpsY": "18.508767 ",
            "status": "0",
            "subjectName": "海航YOHO湾"
        }];
        if (markers.length > 0) {
            markerClusterer.clearMarkers(markers);
        }
        markers = [];
        if (projectData == null) {
            return;
        }
        var sectionList = projectData;

        for (var i = 0; i < sectionList.length; i++) {
            if (sectionList[i].gpsX != null && sectionList[i].gpsY != null) {
                var point = new BMap.Point(sectionList[i].gpsX, sectionList[i].gpsY);
                //addMarker(sectionList[i], point, markers);
            }
        }
    }, 100)
}


function addMarker(sectionArea, point, markers) {
    //设置房建类的和市政类的颜色不同
    var myIcon = new BMap.Icon("/img/location.png", new BMap.Size(34, 34), {
        anchor: new BMap.Size(17, 32)
    });
    var marker = new BMap.Marker(point, {
        icon: myIcon
    });
    //设置文本标注
    var opts = {
        position: point, // 指定文本标注所在的地理位置
        offset: new BMap.Size(0, 0) //设置文本偏移量
    }

    var content = "&nbsp;&nbsp;" + "东经：" + sectionArea.gpsX + "<br>&nbsp;&nbsp;北纬：" + sectionArea.gpsY + "&nbsp;&nbsp;&nbsp</br>" +
        "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp";
    // var content = "<div style ='float:left; margin-right: 10px;width:25%;height:86px;'><img src='/images/u2404.png' 'width ='100%' height ='100%'></div>" + "<div style='height:100%;'><h4> 工程信息 </h4><p><span style='font-size:10px'>" + sectionArea.sectionName + "</span> </p>" + "<p><a href = 'javascript:void(0);' style = 'color:#96C9FE' onclick = 'toSection(\"" + sectionArea.sectionId + "\")' > 进入项目部 </a></p>" + "</div>";

    //var content = '<div style="font-size: 12px; padding: 5px 0px; overflow: hidden;"><p style="padding: 0px; margin: 0px; line-height: 18px; font-size: 12px; color: rgb(77, 77, 77);">地址：海南省万宁市日月桥</p><p style="padding: 0px; margin: 0px; line-height: 18px; font-size: 12px; color: rgb(127, 127, 127);">标签：旅游景点</p></div>'
    // var content =
    //     "<h4 style='margin:0 0 5px 0;padding:0.2em 0'>" + sectionArea.sectionName + "</h4>" +
    //     "<p style='margin:0;line-height:1.5;font-size:13px;'>" + "<span>" + "建设规模：1123平方米" + "</span>" + "&nbsp;&nbsp;&nbsp<span style='text-indent:2em'>" + "总造价：1123平方米" + "</span>" + "</p>" +
    //     "<p style='margin:0;line-height:1.5;font-size:13px;'>建设单位：海南香水皇家湾海洋花园有限公司</p>" +
    //     "<p style='margin:0;line-height:1.5;font-size:13px;'>总包单位：北京华江建设有限公司</p>" +
    //     "<div style='font-size: 12px;margin-top:4px;position:relative'><table style='width:80%;'><tbody><tr><td>项目信息</td><td>责任主体</td><td>监督记录</td></tr><tr><td>材料检测</td><td>远程视频</td><td>劳务实名</td></tr><tr><td>扬尘监测</td><td>建机信息</td><td>责任保险</td></tr></tbody></table> " + "<a href='javascript:void(0);' style='position:absolute;top:12px;right:0;width:60px;height:28px;line-height:20px;padding:4px;border:1px solid #ddd'>点击进入</a>" + "</div>"
    // "</div>";
    var label = new BMap.Label(content, opts); // 创建文本标注对象
    label.setStyle({
        color: "white",
        fontSize: "14px",
        height: "28px",
        lineHeight: "28px",
        fontFamily: "微软雅黑",
        backgroundColor: "rgba(28, 43, 145, 1)",
        border: "1px solid rgba(0, 162, 255, 1)"
    });
    map.addOverlay(marker);
    var steelContent = "<h4 style='margin:0 0 5px 0;padding:0.2em 0'>工程名称：" + '123' + "</h4>" +
        "<p style='margin:0;line-height:1.5;font-size:13px;'>地址：" + '456' + "</p>"
    var steelOpts = {
        width: 0, //信息窗口宽度
        height: 0, //信息窗口高度
        title: "工程信息", //信息窗口标题
        enableMessage: true //设置允许信息窗发送短息
    }
    //添加鼠标滑过时打开自定义信息窗口事件
    marker.addEventListener("mouseover", function () {
        this.openInfoWindow(new BMap.InfoWindow(content));
    });
    markers.push(marker);
    markerArr.push(marker);
}


var map;
var markerArr = new Array();
var markers = [];
var markerClusterer = new BMapLib.MarkerClusterer(map, {
    markers: markers
});